/*
=======================================================================

  BOTS Main Menu

=======================================================================
*/

#include "ui_local.h"
#include "ui_BOTS.h"

#define INGAME_FRAME					"menu/art/addbotframe"

#define BOTS_MAINMENU_CLASSCOMMANDS			1
#define BOTS_MAINMENU_TEAMCOMMANDS			2
#define BOTS_MAINMENU_GENERALCOMMANDS		3
#define BOTS_MAINMENU_EXECUTE_CLASS_SCRIPT	4
#define BOTS_MAINMENU_CHANGE_TEAM			5
#define BOTS_MAINMENU_CHANGE_CLASS			6
#define BOTS_MAINMENU_Q3A_MAIN_MENU			7


// define BOTS UI globals
vec4_t color_bots_menu = {0.00, 1.00, 0.25, 1.00};

typedef struct 
{
  menuframework_s menu;  
  menubitmap_s	frame;

  menutext_s	title;
  menutext_s	classCommands;
  menutext_s	teamCommands;
  menutext_s	generalCommands;
  menutext_s	teamRadio;
  menutext_s	shoutMenu;
  menutext_s	excuteClassScript;
  menutext_s	changeTeam;
  menutext_s	changeClass;
  menutext_s	q3aMainMenu;
  menutext_s	cancel;
} BOTSMainmenu_t;

BOTSMainmenu_t s_BOTSMainmenu;

/*
=================
BOTS_MainMenu_Event
callback routine
=================
*/
void UI_Q3AMainMenu( void );

void BOTS_MainMenu_Event( void *ptr, int notification ) 
{
	int classtype = BOTS_GetClassType();

	if( notification != QM_ACTIVATED )
		return;

	// any event will kill the menu
	UI_PopMenu();

	switch( ((menucommon_s*)ptr)->id ) 
	{
	case BOTS_CANCEL:
		break;
	case BOTS_MAINMENU_CLASSCOMMANDS:
		{
			switch (classtype)
			{
			case BOTS_CAPTAIN:
				BOTS_CaptainCommandsMenu_f();
				break;
			case BOTS_BODYGUARD:
				BOTS_BodyguardCommandsMenu_f();
				break;
			case BOTS_SNIPER:
				BOTS_SniperCommandsMenu_f();
				break;
			case BOTS_SOLDIER:
				BOTS_SoldierCommandsMenu_f();
				break;
			case BOTS_BERZERKER:
				BOTS_BerzerkerCommandsMenu_f();
				break;
			case BOTS_INFILTRATOR:
				BOTS_InfiltratorCommandsMenu_f();
				break;
			case BOTS_KAMIKAZEE:
				BOTS_KamikazeeCommandsMenu_f();
				break;
			case BOTS_NURSE:
				BOTS_NurseCommandsMenu_f();
				break;
			case BOTS_SCIENTIST:
				BOTS_ScientistCommandsMenu_f();
				break;
			}
		}
		break;
		// end BOTS_MAINMENU_CLASSCOMMANDS

	case BOTS_MAINMENU_TEAMCOMMANDS:
		BOTS_TeamCommandsMenu_f();
		break;
	case BOTS_MAINMENU_GENERALCOMMANDS:
		BOTS_GeneralCommandsMenu_f();
		break;
	case BOTS_MAINMENU_EXECUTE_CLASS_SCRIPT:
		trap_Cmd_ExecuteText( EXEC_APPEND, "myclass\n" );
		break;
	case BOTS_MAINMENU_CHANGE_TEAM:
		BOTS_TeamJoinMenu_f();
		break;
	case BOTS_MAINMENU_CHANGE_CLASS:
		BOTS_ClassJoinMenu_f();
		break;
	case BOTS_MAINMENU_Q3A_MAIN_MENU:
		UI_Q3AMainMenu();
		break;

	// oops - not a valid choice
	default:
		Com_Printf("%i is not a valid choice\n", ((menucommon_s*)ptr)->id);
		break;
	} // switch 
}

/*
=================
BOTS_MainMenu_Cache
=================
*/
void BOTS_MainMenu_Cache( void ) {
	trap_R_RegisterShaderNoMip( INGAME_FRAME );
}

/*
=================
BOTS_MainMenu_Init

BOTS_CAPTAIN       1
BOTS_BODYGUARD     2
BOTS_SNIPER        3
BOTS_SOLDIER       4
BOTS_BERZERKER     5
BOTS_INFILTRATOR   6
BOTS_KAMIKAZEE     7
BOTS_NURSE         8
BOTS_SCIENTIST     9
=================
*/
void BOTS_MainMenu_Init() 
{
	int		y;
	static char className[100];
	int classtype = BOTS_GetClassType();

	BOTS_MainMenu_Cache();

	strcpy(className, "");

	// get the string for the class
	switch (classtype)
	{
	case BOTS_CAPTAIN:
		strcpy(className, "CAPTAIN");
		break;
	case BOTS_BODYGUARD:
		strcpy(className, "BODYGUARD");
		break;
	case BOTS_SNIPER:
		strcpy(className, "SNIPER");
		break;
	case BOTS_SOLDIER:
		strcpy(className, "SOLDIER");
		break;
	case BOTS_BERZERKER:
		strcpy(className, "BERZERKER");
		break;
	case BOTS_INFILTRATOR:
		strcpy(className, "INFILTRATOR");
		break;
	case BOTS_KAMIKAZEE:
		strcpy(className, "KAMIKAZEE");
		break;
	case BOTS_NURSE:
		strcpy(className, "NURSE");
		break;
	case BOTS_SCIENTIST:
		strcpy(className, "SCIENTIST");
		break;
	}
	
	strcat (className, " COMMANDS MENU");

	memset( &s_BOTSMainmenu, 0 ,sizeof(BOTSMainmenu_t) );
	s_BOTSMainmenu.menu.wrapAround = qtrue;
	s_BOTSMainmenu.menu.fullscreen = qfalse;

	s_BOTSMainmenu.frame.generic.type		= MTYPE_BITMAP;
	s_BOTSMainmenu.frame.generic.flags		= QMF_INACTIVE;
	s_BOTSMainmenu.frame.generic.name		= INGAME_FRAME;
	s_BOTSMainmenu.frame.generic.x			= 320-233;//142;
	s_BOTSMainmenu.frame.generic.y			= 240-166;//118;
	s_BOTSMainmenu.frame.width				= 466;//359;
	s_BOTSMainmenu.frame.height				= 332;//256;

	y = 96;
	y += BOTS_VERTICAL_SPACING;
	s_BOTSMainmenu.title.generic.type		= MTYPE_PTEXT;
	s_BOTSMainmenu.title.generic.flags		= QMF_CENTER_JUSTIFY;
	s_BOTSMainmenu.title.generic.x			= 320;
	s_BOTSMainmenu.title.generic.y			= y;
	s_BOTSMainmenu.title.string				= "B.o.t.S Main Menu";
	s_BOTSMainmenu.title.color				= color_bots_menu;
	s_BOTSMainmenu.title.style				= UI_CENTER|UI_SMALLFONT;

	// skip a space
	y += BOTS_VERTICAL_SPACING;

	y += BOTS_VERTICAL_SPACING;
	s_BOTSMainmenu.classCommands.generic.type		= MTYPE_PTEXT;
	s_BOTSMainmenu.classCommands.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_BOTSMainmenu.classCommands.generic.x			= 320;
	s_BOTSMainmenu.classCommands.generic.y			= y;
	s_BOTSMainmenu.classCommands.generic.id			= BOTS_MAINMENU_CLASSCOMMANDS;
	s_BOTSMainmenu.classCommands.generic.callback	= BOTS_MainMenu_Event; 
	s_BOTSMainmenu.classCommands.string				= className;
	s_BOTSMainmenu.classCommands.color				= color_bots_menu;
	s_BOTSMainmenu.classCommands.style				= UI_CENTER|UI_SMALLFONT;
	if (classtype == 0) {
		s_BOTSMainmenu.classCommands.generic.flags |= QMF_GRAYED;
	}

	y += BOTS_VERTICAL_SPACING;
	s_BOTSMainmenu.teamCommands.generic.type		= MTYPE_PTEXT;
	s_BOTSMainmenu.teamCommands.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_BOTSMainmenu.teamCommands.generic.x			= 320;
	s_BOTSMainmenu.teamCommands.generic.y			= y;
	s_BOTSMainmenu.teamCommands.generic.id			= BOTS_MAINMENU_TEAMCOMMANDS;
	s_BOTSMainmenu.teamCommands.generic.callback	= BOTS_MainMenu_Event; 
	s_BOTSMainmenu.teamCommands.string				= "TEAM COMMANDS MENU";
	s_BOTSMainmenu.teamCommands.color				= color_bots_menu;
	s_BOTSMainmenu.teamCommands.style				= UI_CENTER|UI_SMALLFONT;

	y += BOTS_VERTICAL_SPACING;
	s_BOTSMainmenu.generalCommands.generic.type		= MTYPE_PTEXT;
	s_BOTSMainmenu.generalCommands.generic.flags	= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_BOTSMainmenu.generalCommands.generic.x		= 320;
	s_BOTSMainmenu.generalCommands.generic.y		= y;
	s_BOTSMainmenu.generalCommands.generic.id		= BOTS_MAINMENU_GENERALCOMMANDS;
	s_BOTSMainmenu.generalCommands.generic.callback	= BOTS_MainMenu_Event; 
	s_BOTSMainmenu.generalCommands.string			= "GENERAL COMMANDS MENU";
	s_BOTSMainmenu.generalCommands.color			= color_bots_menu;
	s_BOTSMainmenu.generalCommands.style			= UI_CENTER|UI_SMALLFONT;

	y += BOTS_VERTICAL_SPACING;
	s_BOTSMainmenu.excuteClassScript.generic.type		= MTYPE_PTEXT;
	s_BOTSMainmenu.excuteClassScript.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_BOTSMainmenu.excuteClassScript.generic.x			= 320;
	s_BOTSMainmenu.excuteClassScript.generic.y			= y;
	s_BOTSMainmenu.excuteClassScript.generic.id			= BOTS_MAINMENU_EXECUTE_CLASS_SCRIPT;
	s_BOTSMainmenu.excuteClassScript.generic.callback	= BOTS_MainMenu_Event; 
	s_BOTSMainmenu.excuteClassScript.string				= "EXECUTE CLASS SCRIPT";
	s_BOTSMainmenu.excuteClassScript.color				= color_bots_menu;
	s_BOTSMainmenu.excuteClassScript.style				= UI_CENTER|UI_SMALLFONT;
	if (classtype == 0) {
		s_BOTSMainmenu.excuteClassScript.generic.flags |= QMF_GRAYED;
	}

	y += BOTS_VERTICAL_SPACING;
	s_BOTSMainmenu.changeTeam.generic.type			= MTYPE_PTEXT;
	s_BOTSMainmenu.changeTeam.generic.flags			= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_BOTSMainmenu.changeTeam.generic.x				= 320;
	s_BOTSMainmenu.changeTeam.generic.y				= y;
	s_BOTSMainmenu.changeTeam.generic.id			= BOTS_MAINMENU_CHANGE_TEAM;
	s_BOTSMainmenu.changeTeam.generic.callback		= BOTS_MainMenu_Event; 
	s_BOTSMainmenu.changeTeam.string				= "CHANGE TEAM";
	s_BOTSMainmenu.changeTeam.color					= color_bots_menu;
	s_BOTSMainmenu.changeTeam.style					= UI_CENTER|UI_SMALLFONT;

	y += BOTS_VERTICAL_SPACING;
	s_BOTSMainmenu.changeClass.generic.type			= MTYPE_PTEXT;
	s_BOTSMainmenu.changeClass.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_BOTSMainmenu.changeClass.generic.x			= 320;
	s_BOTSMainmenu.changeClass.generic.y			= y;
	s_BOTSMainmenu.changeClass.generic.id			= BOTS_MAINMENU_CHANGE_CLASS;
	s_BOTSMainmenu.changeClass.generic.callback		= BOTS_MainMenu_Event; 
	s_BOTSMainmenu.changeClass.string				= "CHANGE CLASS";
	s_BOTSMainmenu.changeClass.color				= color_bots_menu;
	s_BOTSMainmenu.changeClass.style				= UI_CENTER|UI_SMALLFONT;

	y += BOTS_VERTICAL_SPACING;
	s_BOTSMainmenu.q3aMainMenu.generic.type			= MTYPE_PTEXT;
	s_BOTSMainmenu.q3aMainMenu.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_BOTSMainmenu.q3aMainMenu.generic.x			= 320;
	s_BOTSMainmenu.q3aMainMenu.generic.y			= y;
	s_BOTSMainmenu.q3aMainMenu.generic.id			= BOTS_MAINMENU_Q3A_MAIN_MENU;
	s_BOTSMainmenu.q3aMainMenu.generic.callback		= BOTS_MainMenu_Event; 
	s_BOTSMainmenu.q3aMainMenu.string				= "QUAKE 3 MAIN MENU";
	s_BOTSMainmenu.q3aMainMenu.color				= color_bots_menu;
	s_BOTSMainmenu.q3aMainMenu.style				= UI_CENTER|UI_SMALLFONT;

	// skip a space
	y += BOTS_VERTICAL_SPACING;

	y += BOTS_VERTICAL_SPACING;
	s_BOTSMainmenu.cancel.generic.type		= MTYPE_PTEXT;
	s_BOTSMainmenu.cancel.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_BOTSMainmenu.cancel.generic.x			= 320;
	s_BOTSMainmenu.cancel.generic.y			= y;
	s_BOTSMainmenu.cancel.generic.id		= BOTS_CANCEL;
	s_BOTSMainmenu.cancel.generic.callback	= BOTS_MainMenu_Event; 
	s_BOTSMainmenu.cancel.string			= "CANCEL";
	s_BOTSMainmenu.cancel.color				= color_bots_menu;
	s_BOTSMainmenu.cancel.style				= UI_CENTER|UI_SMALLFONT;
	
	Menu_AddItem( &s_BOTSMainmenu.menu, &s_BOTSMainmenu.frame );
	Menu_AddItem( &s_BOTSMainmenu.menu, &s_BOTSMainmenu.title );
	Menu_AddItem( &s_BOTSMainmenu.menu, &s_BOTSMainmenu.classCommands );
	Menu_AddItem( &s_BOTSMainmenu.menu, &s_BOTSMainmenu.teamCommands );
	Menu_AddItem( &s_BOTSMainmenu.menu, &s_BOTSMainmenu.generalCommands );
	Menu_AddItem( &s_BOTSMainmenu.menu, &s_BOTSMainmenu.excuteClassScript );
	Menu_AddItem( &s_BOTSMainmenu.menu, &s_BOTSMainmenu.changeTeam );
	Menu_AddItem( &s_BOTSMainmenu.menu, &s_BOTSMainmenu.changeClass );
	Menu_AddItem( &s_BOTSMainmenu.menu, &s_BOTSMainmenu.q3aMainMenu );
	Menu_AddItem( &s_BOTSMainmenu.menu, &s_BOTSMainmenu.cancel );
}

/*
=================
BOTS_MainMenu_f
=================
*/
void BOTS_MainMenu_f( void ) 
{
	// force as top level menu
	uis.menusp = 0;  

	// set menu cursor to a nice location
	uis.cursorx = 319;
	uis.cursory = 80;

	// setup the menu structure
	BOTS_MainMenu_Init();

	// show the menu
	UI_PushMenu( &s_BOTSMainmenu.menu );

}
